package com.lanou.horo.zhuizhui.utility.imageLoader;

import android.app.Application;
import android.content.Context;
import android.util.Log;


import com.lanou.horo.zhuizhui.entity.greendao.DaoMaster;
import com.lanou.horo.zhuizhui.entity.greendao.DaoSession;
import com.lanou.horo.zhuizhui.entity.greendao.User_Message;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Risky on 15/10/21.
 */
public class BaseApplication extends Application {


    private static DaoMaster daoMaster;
    private static DaoSession daoSession;
    private static Context context;
    private static boolean islogin = false;
    private static User_Message user;

    public static User_Message getUser() {
        return user;
    }

    public static void setUser(User_Message user) {
        BaseApplication.user = user;
    }

    public static boolean islogin() {
        return islogin;
    }

    public static void setIslogin(boolean islogin) {
        BaseApplication.islogin = islogin;
    }

    public static DaoMaster getDaoMaster() {
        if (daoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, "lanou",
                    null);

            daoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return daoMaster;
    }

    public static DaoSession getDaoSession() {
        if (daoSession == null) {
            if (daoMaster == null)
                getDaoMaster();

            daoSession = daoMaster.newSession();
        }
        return daoSession;
    }


    @Override
    public void onCreate() {
        super.onCreate();

        context = this;
//        context = getApplicationContext();
        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

    }


    public static Context getContext() {
        return context;
    }
}
